package com.ignoreexception.bean.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author xD
 * @since 2022/12/22 19:56
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseRespVo {
    // code 取值0表示成功，10000表示失败
    private Integer code;

    // message只有当code=10000时才会去取
    private String message;

    // 如果code是10000，不会取data
    // 只有当code是0时，才可能会去取data，究竟要不要data，还需要看具体业务场景
    private Object data;

    // {"code":0}
    public static BaseRespVo ok() {
        return ok(null);
    }

    public BaseRespVo(Integer code, Object data) {
        this.code = code;
        this.data = data;
    }

    // {"code":0,"data":{"token":"admin","name":"admin"}}
    public static BaseRespVo ok(Object data) {
        return new BaseRespVo(200, data);
    }

    // {"code":10000,"message":"该账号不存在"}
    public static BaseRespVo error(String message) {
        return new BaseRespVo(404, message, null);
    }

    // {"code":1000,"message":"你不能删除admin账号!"}
    public static BaseRespVo error1(String message) {
        return new BaseRespVo(1000, message, null);
    }
}
